'''
Created on 13-Jul-2010

@author: asa
'''
import Contribution

class Comment(Contribution.Contribution):
    
    def __init__(self, contributor, text, parentId = -1):
        Contribution.Contribution.__init__(self)
        self.contributors.append(contributor)
        self.id = -1
        self.text = text
        self.parentId = parentId

    def addRating(self, rater, rating):
        if self.rating.has_key(rater):
            self.rating[rater].rating = rating
        else:
            Contribution.Contribution.addRating(self, rater, rating)

    def __cmp__(self, o):
        if isinstance(o, Comment):
            return self.id == o.id
        else:
            return False
        
    def __str__(self):
        temp = "<comment id=\"comment_" + str(self.id) + "\""
        if self.parentId != -1:
            temp += " parentid=\"comment_" + str(self.parentId) + "\""
        temp += ">\n" \
             + "<username>" + self.contributors[0] + "</username>\n" \
             + "<timestamp>" + str(self.timestamp) + "</timestamp>\n" \
             + "<text>" + self.text + "</text>\n" \
             + "</comment>"
        return temp
        
if __name__=="__main__":
    contribution = Comment("asa", "test", -1)